<?php
/**
 * Settings Controller class
 * @author 		TAMDV
 * @date		2008 08 06 (yyyy MM dd)
 * @package    	Joomus.JBS
 * @subpackage 	Components
 * @link 		http://localhost/jbschedule/administrator/index.php?option=com_jbschedule
 * @license		GNU/GPL
 */
jimport('joomla.application.component.controller');
// no direct access
//defined('_JEXEC') or die('Restricted access');

class JBSControllerSettings extends JController {
	/**
 	 * constructor (registers additional tasks to methods)
	 * @return void
	 */
	function __construct()
	{
		parent::__construct();

		// Register Extra tasks
	}

	function display()
	{
		if (!JBSRoles :: checkPermission($this, JBSConfig :: $VIEW_SETTINGS, 'index.php?option=com_jbschedule', JText :: _('VIEW SETTINGS').' - '.JText :: _('NO PERMISSION'))){
			return;
		}
		/*JRequest::setVar( 'view', 'settings' );
		JRequest::setVar( 'layout', 'list'  );

		parent::display();*/
		$this->edit();
	}

	/**
	 * display the edit form
	 * @return void
	 */
	function edit()
	{
		if ($this->getTask() === 'edit') {
			if (!JBSRoles :: checkPermission($this, JBSConfig :: $EDIT_SETTINGS, 'index.php?option=com_jbschedule&controller=settings', JText :: _('EDIT SETTINGS').' - '.JText :: _('NO PERMISSION')))
				return;
		}
		JRequest::setVar( 'view', 'settings' );
		JRequest::setVar( 'layout', 'form'  );
//		JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}

	/**
	 * save a record (and redirect to main page)
	 * @return void
	 */
	function save()
	{
		$model = $this->getModel('settings');
		if ($model->store($post)) {
			$msg = JText::_( 'SAVED' );

			$session = &JSession::getInstance(null, null);
			$settings = Utils::loadSetting();
			$session->set('settings', $settings);

		} else {
			$msg = JText::_( 'NOT SAVED' );
		}

		// Check the table in so it can be edited.... we are done with it anyway
		$link = 'index.php?option=com_jbschedule&controller=settings';
		$this->setRedirect($link, $msg);
	}
}

?>